import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:nylo_framework/nylo_framework.dart';

class ImageWidget extends StatelessWidget {
  final String imageUrl;
  final BoxFit fit;
  final Key? key;

  ImageWidget({
    this.key,
    required this.imageUrl,
    this.fit = BoxFit.cover,
  }) : super(key: key);

  String get baseUrl => getEnv('DOUBAN_API');

  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      imageUrl: imageUrl,
      fit: fit,
      httpHeaders: {
        'Referer': baseUrl,
        'User-Agent':
            'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)',
      },
      placeholder: (context, url) => CupertinoActivityIndicator(),
      errorWidget: (context, url, error) => Icon(Icons.error),
    );
  }
}
